package com.xqzgj.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xqzgj.common.annotation.Log;
import com.xqzgj.common.core.controller.BaseController;
import com.xqzgj.common.core.domain.AjaxResult;
import com.xqzgj.common.enums.BusinessType;
import com.xqzgj.system.domain.StockCheck;
import com.xqzgj.system.service.IStockCheckService;
import com.xqzgj.common.utils.poi.ExcelUtil;
import com.xqzgj.common.core.page.TableDataInfo;

/**
 * 库存盘点Controller
 */
@RestController
@RequestMapping("/system/check")
public class StockCheckController extends BaseController {
    @Autowired
    private IStockCheckService stockCheckService;

    /**
     * 查询库存盘点列表
     */
    @PreAuthorize("@ss.hasPermi('system:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(StockCheck stockCheck) {
        startPage();
        List<StockCheck> list = stockCheckService.selectStockCheckList(stockCheck);
        return getDataTable(list);
    }

    /**
     * 导出库存盘点列表
     */
    @PreAuthorize("@ss.hasPermi('system:check:export')")
    @Log(title = "库存盘点", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StockCheck stockCheck) {
        List<StockCheck> list = stockCheckService.selectStockCheckList(stockCheck);
        ExcelUtil<StockCheck> util = new ExcelUtil<StockCheck>(StockCheck.class);
        return util.exportExcel(list, "库存盘点数据");
    }

    /**
     * 获取库存盘点详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:check:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(stockCheckService.selectStockCheckById(id));
    }

    /**
     * 新增库存盘点
     */
    @PreAuthorize("@ss.hasPermi('system:check:add')")
    @Log(title = "库存盘点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockCheck stockCheck) {
        return toAjax(stockCheckService.insertStockCheck(stockCheck));
    }

    /**
     * 修改库存盘点
     */
    @PreAuthorize("@ss.hasPermi('system:check:edit')")
    @Log(title = "库存盘点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockCheck stockCheck) {
        return toAjax(stockCheckService.updateStockCheck(stockCheck));
    }

    /**
     * 删除库存盘点
     */
    @PreAuthorize("@ss.hasPermi('system:check:remove')")
    @Log(title = "库存盘点", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(stockCheckService.deleteStockCheckByIds(ids));
    }

    /**
     * 审核库存盘点
     */
    @PreAuthorize("@ss.hasPermi('system:check:approve')")
    @Log(title = "库存盘点", businessType = BusinessType.UPDATE)
    @PutMapping("/approve")
    public AjaxResult approve(@RequestBody StockCheck stockCheck) {
        return toAjax(stockCheckService.approveStockCheck(stockCheck));
    }

    /**
     * 取消审核库存盘点
     */
    @PreAuthorize("@ss.hasPermi('system:check:approve')")
    @Log(title = "库存盘点", businessType = BusinessType.UPDATE)
    @PutMapping("/cancel")
    public AjaxResult cancel(@RequestBody StockCheck stockCheck) {
        return toAjax(stockCheckService.cancelStockCheck(stockCheck));
    }

    /**
     * 完成库存盘点
     */
    @PreAuthorize("@ss.hasPermi('system:check:complete')")
    @Log(title = "库存盘点", businessType = BusinessType.UPDATE)
    @PutMapping("/complete")
    public AjaxResult complete(@RequestBody StockCheck stockCheck) {
        return toAjax(stockCheckService.completeStockCheck(stockCheck));
    }
}